package br.com.comanda.webservice.model;

import static javax.persistence.GenerationType.IDENTITY;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import com.sun.xml.internal.bind.CycleRecoverable;

@XmlRootElement
@Entity
@Table(name = "board", catalog = "comanda")
public class Board implements Serializable, CycleRecoverable {

	private static final long serialVersionUID = -1297413985576638424L;

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	private Integer id;

	@Column(name = "board", nullable = false, length = 20)
	private String board;

	@XmlTransient
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "board")
	private List<Account> accounts = new ArrayList<Account>(0);

	public Board() {
	}

	public Board(String board) {
		this.board = board;
	}

	public Board(String board, List<Account> accounts) {
		this.board = board;
		this.accounts = accounts;
	}

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getBoard() {
		return this.board;
	}

	public void setBoard(String board) {
		this.board = board;
	}

	public List<Account> getAccounts() {
		return this.accounts;
	}

	public void setAccounts(List<Account> accounts) {
		this.accounts = accounts;
	}

	public Object onCycleDetected(Context context) {
		Board board = new Board();
		board.setId(this.id);
		return board;
	}

}
